﻿Imports Mysoft.Map.Application
Imports System.Web
Imports System.Data
Imports Mysoft.Map.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports Mysoft.Map.Caching
Imports System.Xml

Public Class JdjfMng
    '设置购房意向的选项值
    Public Sub SetGfyxValue(ByVal a_page As Page, Optional ByVal a_BlnDefaultLast As Boolean = True)
        Dim sGfyx As New System.Text.StringBuilder
        Dim dtGfyx As DataTable
        Dim pub As New Mysoft.Slxt.Business.PublicMng
        Dim i As Integer
        Dim strSelectedValue As String = String.Empty
        sGfyx.Append("<TABLE cellSpacing=0 cellPadding=0><TBODY><TR>")
        dtGfyx = pub.GetParamFromCache("s_Gfyx", "集团")
        For i = 0 To dtGfyx.Rows.Count - 1
            sGfyx.Append("<TD><INPUT onchange=setNextContentValue(); class=rad2 id=appForm_Gfyx" & i.ToString() & " type=radio value=" & dtGfyx.Rows(i).Item("Text").ToString & " name=appForm_Gfyx></TD>")
            sGfyx.Append("<TD class=radioLabel><LABEL for=appForm_Gfyx" & i.ToString() & ">" & dtGfyx.Rows(i).Item("Text").ToString & "</LABEL></TD>")
            If a_BlnDefaultLast Then
                strSelectedValue = "<INPUT class=rad3 type=hidden value=" & dtGfyx.Rows(i).Item("Text").ToString & " name=Gfyx req=1 ro=0>" '默认最后一个
            Else
                strSelectedValue = "<INPUT class=rad3 type=hidden value=" & dtGfyx.Rows(0).Item("Text").ToString & " name=Gfyx req=1 ro=0>" '默认第一个
            End If
        Next
        sGfyx.Append("</TR></TBODY></TABLE>")
        a_page.ClientScript.RegisterStartupScript(Me.GetType(), "Gfyx", "appForm.Gfyx.previousSibling.outerHTML='" & sGfyx.ToString() & "'; appForm.Gfyx.outerHTML = '" & strSelectedValue & "';", True)
    End Sub

    '设置关键行为的选项值
    Public Sub SetGjxwValue(ByVal a_page As Page)
        Dim sGjxw As New System.Text.StringBuilder
        Dim dtGjxw As DataTable
        Dim pub As New Mysoft.Slxt.Business.PublicMng
        Dim i As Integer
        sGjxw.Append("<TABLE style='TABLE-LAYOUT: fixed' cellSpacing=0 cellPadding=0 width='100%'><TBODY><TR><TD id=tdGjxw width=80>关键行为 </TD>")
        dtGjxw = pub.GetParamFromCache("s_Gjxw", "集团")
        For i = 0 To dtGjxw.Rows.Count - 1
            sGjxw.Append("<TD><INPUT id='Gjxw" & dtGjxw.Rows(i).Item("Value").ToString().Replace(".", String.Empty) & "' style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; WIDTH: 20px; BORDER-BOTTOM: medium none' type=checkbox name=chkGjxw>" & dtGjxw.Rows(i).Item("Text").ToString() & "</TD>")
        Next
        sGjxw.Append("</TR></TBODY></TABLE>")
        a_page.ClientScript.RegisterStartupScript(Me.GetType(), "Gjxw", "_td_appForm_Gjxw.innerHTML=""" & sGjxw.ToString() & """;", True)
    End Sub

    Public Function GetMainMedia() As DataTable
        Dim strSql As String = "SELECT MainMediaName AS [Text],MainMediaCode AS [Value] FROM s_MainMedia Order By MainMediaCode"
        Dim DTTemp As DataTable

        ' 声明缓存Key
        Dim strCacheKey As String = "MainMedia"
        ' 声明 Cache
        Dim myCache As System.Web.Caching.Cache
        Dim _context As HttpContext = HttpContext.Current
        If Not _context Is Nothing Then
            myCache = _context.Cache
        Else
            myCache = HttpRuntime.Cache
        End If

        DTTemp = myCache.Get(strCacheKey)
        If Not DTTemp Is Nothing Then
            Return DTTemp
        End If

        DTTemp = MyDB.GetDataTable(strSql)
        If DTTemp.Rows.Count > 0 Then
            myCache.Insert(strCacheKey, DTTemp, Nothing, DateTime.Now.AddMinutes(20), TimeSpan.Zero)
            Return DTTemp
        Else
            Return DTTemp
        End If
    End Function

    Public Function SaveGjjl(ByVal strXml As String) As String
        Dim xmlDOM As New XmlDocument
        Dim STR_FAIL_EMPTY As String = "FAIL_EMPTY"
        Dim STR_SUCCESS As String = "SUCCESS"
        Dim STR_FAIL_BC As String = "FAIL_BC"
        xmlDOM.LoadXml(strXml)
        Dim node As XmlNode = xmlDOM.SelectSingleNode("s_Opp2Gjjl/Gjfs")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        node = xmlDOM.SelectSingleNode("s_Opp2Gjjl/Gfyx")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        node = xmlDOM.SelectSingleNode("s_Opp2Gjjl/NextDate")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        node = xmlDOM.SelectSingleNode("s_Opp2Gjjl/Status")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        node = xmlDOM.SelectSingleNode("s_Opp2Gjjl/GjDate")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        node = xmlDOM.SelectSingleNode("s_Opp2Gjjl/OppGUID")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        node = xmlDOM.SelectSingleNode("s_Opp2Gjjl/GjrGUID")
        If node Is Nothing Then
            Return STR_FAIL_EMPTY
        End If

        If node.InnerText = String.Empty Then
            Return STR_FAIL_EMPTY
        End If

        If MyDB.SaveXml(strXml) <> String.Empty Then
            Return STR_SUCCESS
        Else
            Return STR_FAIL_BC
        End If

    End Function
End Class
